<template>
  <div id="app">
    <nav class="main-nav">
      <div class="container">
        <div class="nav-brand">
          <router-link to="/">立石译</router-link>
        </div>
        <div class="nav-menu">
          <router-link to="/" class="nav-link">首页</router-link>
          <router-link to="/about" class="nav-link">关于</router-link>
<!--          <router-link to="/vera" class="nav-link">维拉</router-link>-->
          <router-link to="/translationV2" class="nav-link" v-if="isLoggedIn">翻译V2预览</router-link>
          <router-link to="/translation" class="nav-link" v-if="isLoggedIn">翻译</router-link>
          <router-link to="/register" class="nav-link" v-if="!isLoggedIn">注册</router-link>
          <router-link to="/login" class="nav-link" v-if="!isLoggedIn">登录</router-link>
          <!--          <span class="nav-username" v-if="isLoggedIn">{{ username }}</span>-->
          <a href="#" class="nav-link" v-if="isLoggedIn" @click="logout">退出</a>
        </div>
        <div class="nav-toggle">
          <span></span>
          <span></span>
          <span></span>
        </div>
      </div>
    </nav>
    <div class="app-content">
      <router-view/>
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      isLoggedIn: false,
      username: ''
    }
  },
  created() {
    this.checkLoginStatus();
  },
  methods: {
    checkLoginStatus() {
      this.isLoggedIn = !!localStorage.getItem('isLoggedIn');
      // 从localStorage获取用户名，如果不存在则使用默认值
      this.username = localStorage.getItem('username') || '用户';
    },
    logout() {
      localStorage.removeItem('isLoggedIn');
      localStorage.removeItem('username');
      this.isLoggedIn = false;
      this.username = '';
      this.$router.push('/');
      this.$notify.success(`您已成功退出登录，`)
    }
  },
  watch: {
    '$route'() {
      this.checkLoginStatus();
    }
  }
}
</script>

<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Arial', sans-serif;
  background-color: #0a192f;
  color: #ccd6f6;
  line-height: 1.6;
}

#app {
  min-height: 100vh;
}

.main-nav {
  background: rgba(10, 25, 47, 0.9);
  backdrop-filter: blur(10px);
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 1000;
  border-bottom: 1px solid #112240;
  padding: 1rem 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-brand a {
  font-size: 1.8rem;
  font-weight: bold;
  color: #64ffda;
  text-decoration: none;
  transition: color 0.3s ease;
}

.nav-brand a:hover {
  color: #64ffda;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.nav-link {
  color: #8892b0;
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  transition: all 0.3s ease;
  position: relative;
}

.nav-link:hover {
  color: #64ffda;
}

.nav-link.router-link-exact-active {
  color: #64ffda;
}

.nav-link.router-link-exact-active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #64ffda;
}

.nav-username {
  color: #ccd6f6;
  margin-right: 1rem;
  font-weight: 500;
}

.app-content {
  margin-top: 100px;
  min-height: calc(100vh - 100px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .container {
    flex-direction: column;
    gap: 1rem;
  }

  .nav-menu {
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .app-content {
    margin-top: 150px;
  }
}
</style>